package com.song.JavaThread_day02.ch2_4;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class EventStorage {
	
	
	private int maxSize;
	
	private List<Date> storage;
	
	public  EventStorage()
	{
		maxSize = 10;
		storage = new LinkedList<Date>();
	}
	
	public synchronized void set()
	{
		while(storage.size() == maxSize)
		{
			try {
				System.out.printf("Set is  start to waiting \n");
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		storage.add(new Date());
		System.out.printf("Set : %d \n", storage.size());
		notifyAll();
	}
	
	public synchronized void get()
	{
		while(storage.size() ==0)
		{
			try {
				System.out.printf("Get is  start to waiting \n");
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		System.out.printf("Get : %d  %s \n", storage.size() ,((LinkedList<?>) storage).poll());
		notifyAll();
	}
}
